package com.ngc.mall.common.configure.mybatisPlus;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ngc.mall.common.configure.exception.BusinessException;

public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDomain> extends ServiceImpl<M,T> implements IBaseService<T>{
    @Override
    public Long create(T domain){
       super.save(domain);
        return domain.getId();
    }

    @Override
    public T get(Long id) {
        // 此处无法使用 Wrappers 进行条件设置，无法正确反射到 T 对应的实体类
        T data = this.getById(id);
        if (data == null) {
            throw BusinessException.RESULT_DATA_NONE;
        }
        return data;
    }

    @Override
    public T check(Long id) {
        return get(id);
    }
}
